home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / LIBRARY / CMPLTPAS / SENDMORS.PAS < prev    next >
Pascal/Delphi Source File  |  1988-07-14  |  4KB  |  120 lines

  1. {->>>>SendMorse<<<<--------------------------------------------}
  2. {                                                              }
  3. { Filename : SENDMORS.SRC -- Last Modified 7/2/88              }
  4. {                                                              }
  5. { This procedure converts plain text to audible Morse Code at  }
  6. { a specified code speed and tone frequency.  The times are    }
  7. { fairly accurate and have been tested on a 4.77 Mhz PC and a  }
  8. { 16 Mhz 80386 machine without significant difference in       }
  9. { code speed.  (Turbo's V3.0 DELAY procedure is finally clock  }
  10. { speed independent.)  The useful range of the procedure is    }
  11. { from 10-35 WPM, with best "feel" at 15-25 WPM.               }
  12. {                                                              }
  13. { Text is passed to SendMorse as quoted strings of plain       }
  14. { text.  If two characters are to be sent as one without an    }
  15. { intermediate delay, an asterisk ('*') must precede the two   }
  16. { characters.  This replaces the overbar used in most amateur  }
  17. { literature.                                                  }
  18. {                                                              }
  19. {     From: COMPLETE TURBO PASCAL 5.0  by Jeff Duntemann       }
  20. {    Scott, Foresman & Co., Inc. 1988   ISBN 0-673-38355-5     }
  21. {--------------------------------------------------------------}
  22.  
  23. PROCEDURE SendMorse(PlainText : String;
  24.                     ToneFrequency : Integer;
  25.                     CodeSpeed     : Integer);
  26.  
  27. VAR
  28.   I            : Integer;
  29.   ToneLength   : Integer;
  30.   DitLength    : Integer;
  31.   CodeChar     : String;
  32.   BlendNextTwo : Boolean;
  33.  
  34.  
  35. { Code is passed to local procedure Morse as literal dots and  }
  36. { dashes:  '-.-.' = 'C', and so on.  SendMorse converts from   }
  37. { text to the dot/dash code representation. }
  38.  
  39. PROCEDURE Morse(CodeChar : String);
  40.  
  41. VAR
  42.   I : Integer;
  43.  
  44. BEGIN
  45.   FOR I := 1 TO Length(CodeChar) DO
  46.     BEGIN
  47.       IF CodeChar[1] IN ['.','-'] THEN
  48.         BEGIN
  49.           IF CodeChar[I] = '.' THEN ToneLength := DitLength
  50.             ELSE ToneLength := DitLength * 3;
  51.           Sound(ToneFrequency);
  52.           Delay(ToneLength);
  53.           NoSound;
  54.           Delay(DitLength)
  55.         END
  56.     END
  57. END;
  58.  
  59. BEGIN
  60.   BlendNextTwo := False;
  61.   { Code speed calculation is derived from formulae published in }
  62.   { the 1986 ARRL Handbook, Section 9-8.   I recommend running   }
  63.   { this procedure at 10 WPM or greater; 15-20 WPM is its most   }
  64.   { effective range.  Timer resolution interferes above 35 WPM.  }
  65.   DitLength := Round((1.2 / CodeSpeed) * 1000.0);
  66.   FOR I := 1 TO Length(PlainText) DO IF PlainText[I] = '*' THEN
  67.     BlendNextTwo := TRUE ELSE
  68.     BEGIN
  69.       PlainText[I] := UpCase(PlainText[I]);
  70.       CASE PlainText[I] OF
  71.         'A' : CodeChar := '.-';
  72.         'B' : CodeChar := '-...';
  73.         'C' : CodeChar := '-.-.';
  74.         'D' : CodeChar := '-..';
  75.         'E' : CodeChar := '.';
  76.         'F' : CodeChar := '..-.';
  77.         'G' : CodeChar := '--.';
  78.         'H' : CodeChar := '....';
  79.         'I' : CodeChar := '..';
  80.         'J' : CodeChar := '.---';
  81.         'K' : CodeChar := '-.-';
  82.         'L' : CodeChar := '.-..';
  83.         'M' : CodeChar := '--';
  84.         'N' : CodeChar := '-.';
  85.         'O' : CodeChar := '---';
  86.         'P' : CodeChar := '.--.';
  87.         'Q' : CodeChar := '--.-';
  88.         'R' : CodeChar := '.-.';
  89.         'S' : CodeChar := '...';
  90.         'T' : CodeChar := '-';
  91.         'U' : CodeChar := '..-';
  92.         'V' : CodeChar := '...-';
  93.         'W' : CodeChar := '.--';
  94.         'X' : CodeChar := '-..-';
  95.         'Y' : CodeChar := '-.--';
  96.         'Z' : CodeChar := '--..';
  97.         '1' : CodeChar := '.----';
  98.         '2' : CodeChar := '..---';
  99.         '3' : CodeChar := '...--';
  100.         '4' : CodeChar := '....-';
  101.         '5' : CodeChar := '.....';
  102.         '6' : CodeChar := '-....';
  103.         '7' : CodeChar := '--...';
  104.         '8' : CodeChar := '---..';
  105.         '9' : CodeChar := '----.';
  106.         '0' : CodeChar := '-----';
  107.         '?' : CodeChar := '..--..';
  108.         '.' : CodeChar := '.-.-.-';
  109.         ',' : CodeChar := '--..--';
  110.         '/' : CodeChar := '-..-.';
  111.         '$' : CodeChar := '...-..-';
  112.         '-' : CodeChar := '-....-';
  113.         ELSE CodeChar := ''
  114.       END; {CASE}
  115.       Morse(CodeChar);
  116.       IF NOT BlendNextTwo THEN Delay(DitLength * 2);
  117.       BlendNextTwo := FALSE
  118.     END;
  119. END;
  120.